﻿using System;
using System.ComponentModel;
using System.Configuration;
using System.Drawing.Design;
using mki.Backup.Objects.Converters;
using mki.Backup.Objects.Editors;

namespace mki.Backup.Objects
{
	/// <summary>
	/// DB Backup Block
	/// </summary>
	public class DBBackupElement : CustomConfigurationElement
	{
		#region Enums (1)

		/// <summary>
		/// Gets or sets the FTP method.
		/// </summary>
		/// <value>
		/// The FTP method.
		/// </value>
		public enum BackupMethod
		{
			/// <summary>
			/// full backup
			/// </summary>
			Full = 1,

			/// <summary>
			/// differenzial backup
			/// </summary>
			Differential = 2,

			/// <summary>
			/// transaction log backup
			/// </summary>
			TransactionLog
		}

		#endregion Enums

		#region Properties (6)

		/// <summary>
		/// Gets or sets the connection string.
		/// </summary>
		/// <value>
		/// The connection string.
		/// </value>
		[ConfigurationProperty("connectionString", IsRequired = true)]
		[Editor(typeof(ConnectionStringUITypeEditor), typeof(UITypeEditor)), TypeConverter(typeof(ReadOnlyStringConverter))]
		[Description("ConnectionString for the database which should be in backup"), Category("Design")]
		public String ConnectionString
		{
			get { return this["connectionString"].ToString(); }
			set { this["connectionString"] = value; }
		}

		/// <summary>
		/// Gets or sets the name of the database.
		/// </summary>
		/// <value>
		/// The name of the database.
		/// </value>
		[ConfigurationProperty("databaseName", IsRequired = true)]
		[Description("Enter the database name here"), Category("Design")]
		public String DatabaseName
		{
			get { return this["databaseName"].ToString(); }
			set { this["databaseName"] = value; }
		}

		/// <summary>
		/// Gets or sets the method.
		/// </summary>
		/// <value>
		/// The method.
		/// </value>
		[ConfigurationProperty("method", IsRequired = true)]
		[Description("Backupmethod"), Category("Behavior")]
		public BackupMethod Method
		{
			get { return (BackupMethod)this["method"]; }
			set { this["method"] = value; }
		}

		/// <summary>
		/// Gets or sets the name.
		/// </summary>
		/// <value>
		/// The name.
		/// </value>
		[ConfigurationProperty("name", IsRequired = true, IsKey = true)]
		public new String Name
		{
			get { return base["name"].ToString(); }
			set
			{
				base["name"] = value;
				base.OnPropertyChanged("Name");
			}
		}

		/// <summary>
		/// Gets or sets the statement timeout.
		/// </summary>
		/// <value>
		/// The statement timeout.
		/// </value>
		[ConfigurationProperty("statementTimeout", DefaultValue = 90)]
		[Description("Enter the statement timeout here"), Category("Design")]
		public Int32 StatementTimeout
		{
			get { return Int32.Parse(!String.IsNullOrWhiteSpace(this["statementTimeout"].ToString()) ? this["statementTimeout"].ToString() : "0"); }
			set { this["statementTimeout"] = value; }
		}

		/// <summary>
		/// Gets or sets the target directory.
		/// </summary>
		/// <value>
		/// The target directory.
		/// </value>
		[ConfigurationProperty("targetDirectory", IsRequired = true)]
		[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(UITypeEditor)), TypeConverter(typeof(ReadOnlyStringConverter))]
		[Description("Director to store backup file in"), Category("Design")]
		public String TargetDirectory
		{
			get { return this["targetDirectory"].ToString(); }
			set { this["targetDirectory"] = value; }
		}

		#endregion Properties
	}
}